/************************************************************************
Copyright (c) 2010, 2013, C.R. All rights reserved. 

E-mail: crtoyou@gmail.com; crtoyou@163.com

You can redistribute it and/or modify it under the terms of the
GNU Lesser General Public License as published by the
Free Software Foundation version 3 of the License.

This source code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. if not, write to the Free Software Foundation, Inc., 
51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
************************************************************************/

#ifndef __CR_PORTABLE_SUPPORT_H__
#define __CR_PORTABLE_SUPPORT_H__

#include <basetype.h>

#ifndef NULL
#define NULL 0
#endif

typedef void* CR_HANDLE;
#define CR_INVALID_HANDLE ((CR_HANDLE)-1) 

#ifndef byte
typedef unsigned char byte;
#endif 

#ifndef size_t
typedef unsigned int size_t;
#endif 

union uint128
{
	uint64 qw[2];
	uint32 dw[4];
	uint8 by[16];

	uint128(uint64 ql=0, uint64 qh=0)
	{
		qw[0]=ql;
		qw[1]=qh;
	}
};

template <typename T> struct singleton
{
	inline T& operator()(void) const
	{
		static T instance;
		return instance;
	}
};

template <typename type_obj> struct exception
{
	int code;
	type_obj* obj;

	explicit exception(int _e, type_obj* _o = NULL)
		: code(_e), obj(_o)
	{}
};


#endif /* __CR_PORTABLE_SUPPORT_H__ */
